package com.sunyy.codegenerator.config;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author sunyy
 * @date 2025/1/24
 */
@Data
@Configuration
@ConfigurationProperties(prefix = "id-util")
public class SnowflakeConfig {
    private Long workerId;
    private Long dataCenterId;

    @Bean("snowflake")
    public Snowflake getSnowflake() {
        return IdUtil.getSnowflake(workerId, dataCenterId);
    }
}
